#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include "qthread.h"
#include <QMainWindow>
#include <client.h>
#include <canthread.h>
#include <QLabel>
#include <QtSerialPort/QSerialPort>         // 提供访问串口的功能
#include <QtSerialPort/QSerialPortInfo>     // 提供系统中存在的串口信息

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void View_init();
    void progressInit();
    void CANConnect();

    void RS485Data(QString da);
    void RS485BGFData(QString da);
    //温度数据
    float Tem1_1;
    float Tem1_2;
    float Tem1_3;
    float Tem1_4;
    float Tem1_5;
    float Tem1_6;

    void DCDC1Sstate1(QString da);
    void DCDC1Sstate2(QString da);
    //DCDC电压电流、温度数据
    int DC1_inV = 0;
    int DC1_inA = 0;
    int DC1_putV = 0;
    int DC1_putA = 0;
    int ZLQ1_inV = 0;
    int ZLQ1_inA = 0;
    int SQ1Tem = 0;
    int XQ1Tem = 0;
    int DG1Tem = 0;

    QThread thread1;
    Client *client = NULL;
    QThread *thread2 = NULL;
    canThread *can = NULL;

    QString s0 = "00000";
    QString s1 = "00";
    QString s2 = "0";
    QString daV = "0000";
    QString daA = "00";
    QString daW = "00";
    QString daZK = "00";

    //导轨开关控制限值
    int dg1_min = 0;
    int dg1_max = 20;
    int dg2_min = 20;
    int dg2_max = 40;
    int dg3_min = 40;
    int dg3_max = 60;
    int dg4_min = 60;
    int dg4_max = 80;
    int dg5_min = 80;
    int dg5_max = 100;
    int dg6_min = 100;
    int dg6_max = 120;
    int dg7_min = 0;
    int dg7_max = 0;

    void timerEvent(QTimerEvent *event);
    void createIndicatorLabel(QLabel* label, int color, int size, QString number, bool numlock);

private slots:
    void on_openRS4851_clicked();//打开4851
    void on_openRS4852_clicked();//打开4852
    void on_findBtn_clicked();
    void on_findBtn2_clicked();
    void readTemperature();//发送获取温度指令
    void readXYSpeed();//读取X轴+Y轴+速度信息
    void readBug();//读取X轴+Y轴+速度信息

    void on_pushButton_clicked();

    void on_pushButton_2_clicked();

    void on_comboBox_activated(int index);

signals:
    void SIGtocansen(unsigned int ID, std::vector<int> vec);
    void SIGtocancon();                                     //启动CAN按钮发出的信号
    void SIGtocansto();                                     //关闭CAN按钮发出的信号
    void SIG_dwdata(QString da);

private:
    Ui::MainWindow *ui;

    QTimer m_timer;//485定时器1
    QTimer m_timer2;//485定时器1
    QTimer tem_timer;//获取定位数据定时器
    QTimer tem_timer2;//获取温度值定时器
    QSerialPort SerialPort;//串口号1
    QSerialPort SerialPort2;//串口号2

    int refreshTimer; //刷新图像的定时器
    int sampleTimer; //模拟采样的定时器
};
#endif // MAINWINDOW_H
